<template>
  <div v-loading="loading">
    <!-- 面包屑 -->
    <!-- 面包屑组件 -->
    <!-- <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
      <el-breadcrumb-item>
        <img src="@/assets/user/icon.png" alt="" />
        <span class="span">用户管理</span>
      </el-breadcrumb-item>
      <el-breadcrumb-item>
        <span class="span" style="color: #666">认证信息</span>
      </el-breadcrumb-item>
    </el-breadcrumb> -->
    <div class="box">
      <!-- 头部-->
      <!-- 头部-->
      <div class="title">
        <h5></h5>
        <h3>平台认证</h3>
      </div>
      <!-- rzxx有值时 -->
      <template v-if="rzxx">
        <template v-if="restatus != 'succ' || restatus == 'null' || restatus == 'undefined'">
          <div class="null">
            <img src="@/assets/shangpiao/组162.png" alt="" />
            <div>
              <p>暂未认证企业</p>
            </div>
            <div class="submit">
              <div class="btns">
                <div class="btn" @click="goNewlyAttestation">立即认证</div>
              </div>
            </div>
          </div>
        </template>
        <!-- rzxx -->
        <template v-else>
          <h4>企业信息</h4>
          <ul>
            <li>
              <span class="bbb">企业名称</span>
              <div class="inp inps">
                <input v-model="form.entname" type="text" disabled />
              </div>
            </li>
            <li>
              <span class="bbb">统一社会信用代码</span>
              <div class="inp inps">
                <input v-model="form.licenseno" type="text" disabled />
              </div>
            </li>
            <div class="top" v-if="restatus == 'succ'">
              <img src="@/assets/authentication/章.png" alt="" />
            </div>
          </ul>
          <!-- 营业执照 -->
          <div class="license" style="margin-top: 35px">
            <span class="aaa"></span>
            <h5 style="width: 240px; height: 150px; margin-right: 8px">
              <img :src="fileBussiness" alt="" style="width: 100%; height: 100%" />
            </h5>
            <!-- <div class="license-right">
              <div>
                <p>1.营业执照正、副本或复印件加盖公章后的扫描件；</p>
                <p>2.上传文件大小不超过5M；</p>
                <p>3.仅支持bmp、jpeg、png、jpg格式文件。</p>
              </div>
            </div> -->
          </div>
          <!--标题  -->
          <h4>法定代表人信息</h4>
          <ul>
            <li>
              <span class="bbb">姓名</span>
              <div class="inp inps">
                <input v-model="form.mainindname" type="text" disabled />
              </div>
            </li>
            <li>
              <span class="bbb">身份证号</span>
              <div class="inp inps">
                <input v-model="form.fincertNO" type="text" disabled />
              </div>
            </li>
            <li>
              <span class="bbb">手机号</span>
              <div class="inp inps">
                <input v-model="form.fincertTel" type="text" disabled />
              </div>
            </li>
            <div class="top" v-if="restatus == 'succ'">
              <img src="@/assets/authentication/章.png" alt="" />
            </div>
          </ul>
          <!-- 法人身份证正反面 -->
          <div class="license" style="margin-top: 35px">
            <span class="aaa">身份证</span>
            <!-- 正面 -->
            <h5 class="card" style="width: 216px; height: 123px">
              <img :src="fileFront" alt="" />
            </h5>
            <!-- 反面 -->
            <h5 class="card" style="width: 216px; height: 123px">
              <img :src="fileReverse" alt="" />
            </h5>
            <!-- <div class="license-right card-right">
              <div>
                <p>1.上传文件大小不超过5M；</p>
                <p>2.仅支持bmp、jpeg、png、jpg格式文件。</p>
              </div>
            </div> -->
          </div>
          <!-- 经办人信息 -->
          <h4>经办人信息</h4>
          <ul>
            <li>
              <span class="bbb">姓名</span>
              <div class="inp inps">
                <input v-model="form.operatename" type="text" disabled />
              </div>
            </li>
            <li>
              <span class="bbb">身份证号</span>
              <div class="inp inps">
                <input v-model="form.operatecertid" type="text" disabled />
              </div>
            </li>
            <li>
              <span class="bbb">手机号</span>
              <div class="inp inps">
                <input v-model="form.operateTel" type="text" disabled />
              </div>
            </li>
            <div class="top" v-if="restatus == 'succ'">
              <img src="@/assets/authentication/章.png" alt="" />
            </div>
          </ul>
          <!-- 经办人身份证正反面 -->
          <div class="license" style="margin-top: 35px">
            <span class="aaa">身份证</span>
            <!-- 正面 -->
            <h5 class="card" style="width: 216px; height: 123px">
              <img :src="JBRfileFront" alt="" />
            </h5>
            <!-- 反面 -->
            <h5 class="card" style="width: 216px; height: 123px">
              <img :src="JBRfileReverse" alt="" />
            </h5>
            <!-- <div class="license-right card-right">
              <div>
                <p>1.上传文件大小不超过5M；</p>
                <p>2.仅支持bmp、jpeg、png、jpg格式文件。</p>
              </div>
            </div> -->
          </div>
        </template>
        <div class="submit" v-if="restatus == 'succ'">
          <div class="btns">
            <div class="btn" @click="centerDialogVisible = true">重新认证</div>
          </div>
        </div>
      </template>
      <!-- rzxx无值时 -->
      <template v-else>
        <div class="null">
          <img src="@/assets/shangpiao/组162.png" alt="" />
          <div>
            <p>暂未认证企业</p>
          </div>
          <div class="submit">
            <div class="btns">
              <div class="btn" @click="goNewlyAttestation">立即认证</div>
            </div>
          </div>
        </div>
      </template>
    </div>
    <!-- 弹框 -->
    <el-dialog title="提示" :visible.sync="centerDialogVisible" width="30%">
      <!-- 内容区域 -->
      <div class="dialog-center">
        <p>
          <img src="@/assets/authentication/组69.png" alt="" />
          您确定要变更认证信息？
        </p>
      </div>
      <!-- 按钮区域 -->
      <div slot="footer" class="dialog-footer">
        <button class="dialog-footer-bnt btn1" @click="centerDialogVisible = false">取 消</button>
        <button class="dialog-footer-bnt btn2" @click="invite(true)">确 定</button>
      </div>
    </el-dialog>
    <!-- 退出登录弹框 -->
    <el-dialog title="提示" :visible.sync="DialogVisible" width="32%">
      <!-- 内容区域 -->
      <div class="dialog-center">
        <p>
          <img src="@/assets/image/组69.png" alt="" />
          登录信息已过期请重新登录
        </p>
      </div>
      <!-- 按钮区域 -->
      <div slot="footer" class="dialog-footer">
        <button class="dialog-footer-bnt btn1" @click="DialogVisible = false">取 消</button>
        <button class="dialog-footer-bnt btn2" @click="quit()">确 定</button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import { listent, base, getFilePath } from '@/utils'
export default {
  data() {
    return {
      restatus: '',
      loading: true,
      btn: false,
      disabled: false,
      centerDialogVisible: false,
      DialogVisible: false,
      rzxx: null,
      fileBussiness: '', //营业执照
      fileFront: '', //法人正面
      fileReverse: '', //法人反面
      JBRfileFront: '', //经办人正面
      JBRfileReverse: '', //经办人反面
      base: '',
      customerids: '',
      fincertNO: '', //法人身份证，获取图片
      operatecertid: '', //经办人身份证，获取图片
      form: {
        entname: '',
        licenseno: '',
        mainindname: '',
        fincertNO: '',
        fincertTel: '',
        customerid: '',
        phonecode: '',
        operatename: '',
        operatecertid: '',
        operateTel: ''
      },
      forms: {
        entname: '',
        licenseno: '',
        mainindname: '',
        fincertNO: '',
        fincertTel: '',
        customerid: ''
      }
    }
  },
  // 过滤器
  filters: {
    getPhone: function (value) {
      if (value == 0) return value
      value = value.replace(/(\d{3})\d*(\d{4})/, '$1****$2')
      return value
    }
  },
  // 计算属性
  computed: {
    ...mapState(['customerid'])
  },
  mounted() {
    // this.getFilePath();
    this.listent()
    if (this.$route.query.state) {
      this.state = this.$route.query.state
    }
    this.base = base
  },
  methods: {
    // 返回登录页
    quit() {
      this.$router.push('/login')
      sessionStorage.clear()
      setTimeout(() => {
        this.$router.go(0)
      }, 500)
    },
    // 获取表单数据
    async listent() {
      let data = await listent()
      if (data.code == 10000) {
        this.DialogVisible = true
        this.loading = false
        return
      }
      setTimeout(() => {
        this.loading = false
      }, 500)
      if (data.data) {
        this.rzxx = data.data.cooporg
        this.restatus = data.data.cooporg.rzstatus
        this.customerids = data.data.cooporg.customerid
        this.form.entname = data.data.cooporg.entname
        // 统一信用社会代码
        this.form.licenseno = data.data.cooporg.licenseno
        this.form.mainindname = data.data.cooporg.mainindname
        this.form.operatename = data.data.cooporg.operatename
        this.form.operatecertid = this.identity(data.data.cooporg.operatecertid)
        this.form.fincertNO = this.identity(data.data.cooporg.fincertno)
        // 法人身份证
        this.fincertNO = data.data.cooporg.fincertno
        this.form.fincertTel = this.getPhone(data.data.cooporg.fincerttel)
        // 经办人身份证
        this.operatecertid = data.data.cooporg.operatecertid
        this.form.operateTel = this.getPhone(data.data.cooporg.operateTel)

        let flow = data.data.flow
        sessionStorage.setItem('rzstatus', data.data.cooporg.rzstatus)
        sessionStorage.setItem('Phone', data.data.cooporg.fincerttel)
        sessionStorage.setItem('name', data.data.cooporg.mainindname)
        sessionStorage.setItem('idNumber', data.data.cooporg.fincertno)
        sessionStorage.setItem('fraccountid', data.data.fraccountid)
        // 统一社会信用代码
        this.getFileBussinessPath()
        // 法定代表人
        this.getFileFDDBRPath()
        // 经办人
        this.getFileJBRPath()
        if (data.data.cooporg.rzstatus == '90') {
          this.$router.push(`/authentication3?flowId=${flow}`)
        } else if (data.data.cooporg.rzstatus == '02') {
          this.$router.push(`/authentication2`)
        } else if (data.data.cooporg.rzstatus == '01') {
          this.$router.push(`/authentication1`)
        }
        return data.data
      }
    },
    // 手机号脱敏
    getPhone: function (value) {
      if (!value) return value
      value = value.replace(/(\d{3})\d*(\d{4})/, '$1****$2')
      return value
    },
    // 身份证号脱敏
    identity: function (value) {
      if (!value) return value
      value = value.replace(/(\w{6})\w*(\w{4})/, '$1********$2')
      return value
    },
    // 获取营业执照
    async getFileBussinessPath() {
      let customerid = this.customerids + this.form.licenseno
      let { data } = await getFilePath(customerid)
      if (data) {
        for (let i = 0; i < data.length; i++) {
          if (data[i].name == '营业执照') {
            this.fileBussiness = data[i].path
          }
        }
      }
    },
    // 获取图片数据,法人信息
    async getFileFDDBRPath() {
      let customerid = this.customerids + this.fincertNO
      let { data } = await getFilePath(customerid)
      if (data) {
        for (let i = 0; i < data.length; i++) {
          if (data[i].name == '身份证正面') {
            this.fileFront = data[i].path
          } else if (data[i].name == '身份证反面') {
            this.fileReverse = data[i].path
          }
        }
      }
    },
    // 获取图片数据,经办人信息
    async getFileJBRPath() {
      let customerid = this.customerids + this.operatecertid
      let { data } = await getFilePath(customerid)
      if (data) {
        for (let i = 0; i < data.length; i++) {
          if (data[i].name == '身份证正面') {
            this.JBRfileFront = data[i].path
          } else if (data[i].name == '身份证反面') {
            this.JBRfileReverse = data[i].path
          }
        }
      }
    },
    // 点击弹框确认键
    invite(succ) {
      localStorage.setItem('succ', succ)
      this.$router.push(`/authentication`)
      this.centerDialogVisible = false
    },
    // 跳转至企业认证页
    goNewlyAttestation() {
      localStorage.removeItem('succ')
      let rzstatus = sessionStorage.getItem('rzstatus')
      if (rzstatus == 'succ' || rzstatus == '01' || rzstatus == '02') {
        this.$router.push('/authentication1?state=true')
        this.setTime()
      } else {
        this.$router.push('/authentication')
        this.setTime()
      }
    },
    setTime() {
      setTimeout(() => {
        this.$router.go(0)
      }, 1000)
    }
  }
}
</script>

<style lang="scss" scoped>
// 面包屑
.breadcrumb {
  display: flex;
  align-items: center;
  height: 0.3958rem;
  font-size: 0.0833rem;
  background-color: rgb(242, 244, 247);
  .icon {
    margin: 0 0.0521rem 0 0.0208rem;
  }
  .span {
    font-size: 0.0833rem;
    font-family: Source Han Sans SC;
    font-weight: 400;
    color: #999999;
  }
  img {
    width: 0.0938rem;
    height: 0.0938rem;
    margin-right: 0.026rem;
  }
}
// 主体
.box {
  flex: 1;
  box-sizing: border-box;
  width: 100%;
  background: #ffffff;
  border-radius: 6px;
  padding: 0.2604rem;
  // height: 885px;
  overflow: auto;
  // 标题
  .title {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    height: 25px;
    h3 {
      font-size: 22px;
      font-family: Source Han Sans SC;
      font-weight: bold;
      color: #222222;
    }
  }
  h4 {
    font-size: 16px;
    font-family: Source Han Sans SC;
    font-weight: 400;
    color: #4d4d4d;
    margin: 35px 0 15px 0;
  }
  ul {
    position: relative;
    // background-color: #f00;
    li {
      display: flex;
      align-items: center;
      height: 50px;
      margin-bottom: 15px;
      .bbb {
        width: 180px;
        font-size: 16px;
        font-family: Source Han Sans SC;
        font-weight: 400;
        color: #999999;
      }
      .inp {
        width: 400px !important;
        height: 39px !important;
        .message {
          margin-top: -9px;
          font-size: 14px;
          font-family: Source Han Sans SC;
          font-weight: 400;
          color: #ef2d46;
        }
        // background-color: #f00;
        input {
          box-sizing: border-box;
          width: 100%;
          height: 100%;
          font-size: 16px;
          font-family: Source Han Sans SC;
          font-weight: 400;
          color: #4d4d4d;
          padding: 10px;
        }
      }
      .inps {
        border: 1px solid #e0e0e0;
      }
    }
    .top {
      width: 82px;
      height: 65px;
      position: absolute;
      top: -15px;
      left: 500px;
    }
  }
  .license {
    display: flex;
    width: 100%;
    .aaa {
      width: 180px;
      font-size: 16px;
      font-family: Source Han Sans SC;
      font-weight: 400;
      color: #999999;
    }
    .permit {
      position: relative;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      overflow: hidden;
      width: 240px;
      height: 150px;
      background: url(../../assets/authentication/组65.png) no-repeat;
      background-size: 100% 100%;
      margin-right: 15px;
      overflow: hidden;
      cursor: pointer;
      img {
        width: 250px;
        height: 100%;
      }
    }
    .permit-front {
      background: url(../../assets/authentication/组66.png) no-repeat;
      background-size: 100% 100%;
    }
    .permit-reverse {
      background: url(../../assets/authentication/组67.png) no-repeat;
      background-size: 100% 100%;
    }
    .card {
      width: 216px;
      height: 123px;
      margin-right: 8px;
      img {
        width: 100%;
        height: 100%;
      }
    }
    .license-right {
      display: flex;
      flex-direction: column;
      justify-content: flex-end;
      div {
        width: 100%;
        p {
          font-size: 14px;
          font-family: Source Han Sans SC;
          font-weight: 400;
          color: #999999;
          line-height: 24px;
        }
      }
    }
  }
  .ul-timer {
    margin-top: 50px;
    .verify {
      display: flex;
      align-items: center;
      position: relative;
      width: 400px;
      height: 39px;
      input {
        box-sizing: border-box;
        width: 100%;
        height: 100%;
        font-size: 16px;
        font-family: Source Han Sans SC;
        font-weight: 400;
        color: #4d4d4d;
        padding: 10px;
      }
      .timer {
        width: 150px;
        // height: 40px;
        border-radius: 40px;
        position: absolute;
        right: -15px;
        // top: 0px;
        font-size: 16px;
        font-family: Source Han Sans SC;
        font-weight: 400;

        cursor: pointer;
        user-select: none;
      }
    }
    .verifys {
      border: 1px solid #e0e0e0;
    }
  }
  .null {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 70vh;
    // // 小屏
    // @media only screen and (min-width: 900px) and (max-width: 1535px) {
    //   height: 440px;
    // }
    // // 中屏
    // @media only screen and (min-width: 1536px) and (max-width: 1919px) {
    //   height: 440px;
    // }
    // // 大屏
    // @media only screen and (min-width: 1920px) and (max-width: 2580px) {
    //   height: 660px;
    // }
    div {
      text-align: center;
      margin-top: 30px;
      p {
        font-size: 16px;
        font-family: Source Han Sans SC;
        font-weight: 400;
        color: #b3b3b3;
        margin-top: 15px;
      }
    }

    img {
      width: 326px;
      height: 212px;
    }
  }
  .submit {
    width: 100%;
    height: 90px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    margin-top: 30px;
    user-select: none;
    // background-color: #f00;
    // 服务协议
    .agreement {
      display: flex;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 25px;
      text-align: center;
      margin-top: 10px;
      user-select: none;
      span {
        font-size: 14px;
        color: #666;
        margin-left: 7px;
      }
      img {
        width: 15px;
        height: 15px;
        cursor: pointer;
      }
      a {
        font-size: 14px;
        color: #48a0b8;
      }
    }
    .btns {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 100%;
      height: 80px;
      margin-top: 30px;
      user-select: none;
      // background-color: #f00;
      .btn {
        display: flex;
        justify-content: center;
        align-items: center;
        width: 180px;
        height: 34px;
        background: linear-gradient(-90deg, #5d98f8, #4b5af8);
        border-radius: 4px;
        font-size: 18px;
        font-family: Source Han Sans SC;
        font-weight: 400;
        color: #ffffff;
        cursor: pointer;
        user-select: none;
      }
      .btn1 {
        background-color: #bfbfbf;
      }
      // 提交按钮
      .btn3 {
        background-color: #ccc;
        &.active {
          background: linear-gradient(-90deg, #5d98f8, #4b5af8);
        }
      }
    }
  }
  // 弹出框
  .dialog-center {
    width: 90%;
    text-align: center;
    p {
      display: flex;
      justify-content: center;
      align-items: center;
      height: 30px;
      margin-left: 53px;
      font-size: 16px;
      font-family: Source Han Sans SC;
      font-weight: 400;
      color: #4d4d4d;
      img {
        width: 18px;
        height: 18px;
        margin-right: 10px;
      }
    }
  }
  .dialog-footer {
    display: flex;
    justify-content: space-evenly;
    width: 70%;
    margin: 0 auto;
    .dialog-footer-bnt {
      width: 121px;
      height: 31px;
      color: #3f6ef2;
      border: 1px solid #3f6ef2;
      border-radius: 4px;
      background-color: #fff;
    }
    .btn2 {
      color: #fff;
      background: linear-gradient(-90deg, #5d98f8, #4b5af8);
    }
  }
}
::v-deep .el-input__inner {
  width: 400px;
  border-radius: 0;
}
</style>
<style lang="scss">
// 上传
.el-upload--picture-card {
  background-color: rgba(245, 245, 245, 0.1);
  border: 0;
}

.el-upload-list--picture-card .el-upload-list__item {
  width: 250px;
  height: 160px;
  display: flex;
  margin: 0;
  z-index: 888;
}
.el-dialog__header {
  border: 0px;
}

.el-form-item {
  margin-bottom: 0;
}
</style>
